package cn.t.web.user;

import cn.t.dto.user.PasswordLoginRequest;
import cn.t.facade.user.UserLoginFacade;
import cn.t.facade.user.UserSessionFacade;
import cn.t.vo.user.MySaTokenInfoVO;
import cn.t.vo.user.UserSessionVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author l
 */
@Slf4j
@RestController
@RequestMapping("/user")
// "用户登陆服务")
@AllArgsConstructor
public class UserLoginController {


    @PostMapping("login")
    public MySaTokenInfoVO login(@RequestBody PasswordLoginRequest request) {

        // 返回token信息
        return userLoginFacade.login(request.getScenarioCode(), request.getUserName(), request.getPassword()).getMySaTokenInfoVO();
    }


    @GetMapping("session")
    public UserSessionVO getSession() {
        return userSessionFacade.getSession();
    }



    @GetMapping("logout")
    public Boolean logout() {
        userLoginFacade.logout();
        return true;
    }

    @Autowired
    private UserLoginFacade userLoginFacade;

    @Autowired
    private UserSessionFacade userSessionFacade;
}
